package com.hqyj.mana.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;




import com.hqyj.mana.enums.ResultEnum;
import com.hqyj.mana.pojo.FileManagement;
import com.hqyj.mana.pojo.vo.ResultVO;
import com.hqyj.mana.service.FileManagementService;

import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("document")
public class FileManagementController {

	@Autowired
	FileManagementService service;
	
	@RequestMapping("get.do")
	@ResponseBody
	public ResultVO getFileManagementList(){
		Object list;
		ResultVO resultVO = new ResultVO();
		try{
			list = service.selectAllFileManagement();
		}catch(Exception e){
			e.printStackTrace();
			resultVO.setCode(ResultEnum.DATABASE_ERROR.getCode());
			resultVO.setMsg(ResultEnum.DATABASE_ERROR.getMessage());
			return resultVO;
		}
		resultVO.setData(list);
		if(list == null){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	
	@RequestMapping("FileManagementPage.do")
	//锟斤拷锟斤拷Document.jsp页锟斤拷
	public  String FileManagementPage(){
		
		return "FileManagement";
	}
	
	@RequestMapping("add.do")
	@ResponseBody
	public ResultVO add(@RequestBody FileManagement user){
		boolean add = service.add(user);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(add);
		if(add!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	/**
	 * 锟睫革拷
	 * @param user
	 * @return
	 */
	@RequestMapping("update.do")
	@ResponseBody
	public ResultVO update(@RequestBody FileManagement user){
		boolean update = service.update(user);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(update);
		if(update!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
	/**
	 * 删锟斤拷
	 * @param user
	 * @return
	 */
	@RequestMapping("delete.do")
	@ResponseBody
	public ResultVO delete(Integer fileId){
		boolean delete = service.del(fileId);
		ResultVO resultVO = new ResultVO();
		resultVO.setData(delete);
		if(delete!=true){
			resultVO.setCode(ResultEnum.PARAM_ERROR.getCode());
			resultVO.setMsg(ResultEnum.PARAM_ERROR.getMessage());
			return resultVO;
		}	
		resultVO.setCode(ResultEnum.SUCCESS.getCode());
		resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
		return resultVO;
	}
		
	//带条件的查询
		@RequestMapping("selectByCondtion.do")
		@ResponseBody
		public ResultVO selectByCondtion(){
			HashMap<String, Object> hashmap =service.hashCode(null);
			ResultVO resultVO = new ResultVO();
			resultVO.hashCode(hashmap);
			return resultVO;
		}
}
